#基础
list1 = [1, 2, 3, 4, 5, 8]
list1.append(6)
print(list1)
list1.remove(3)
print(list1)
list1[1] = 8
print(list1.index(8))
list1 = [1, 2, 3, 4, 5, 8, 6]
for i in list1:
    print(i,end=' ')
print()
list1 = [1,2,3,4,5,8]
list2 = [10,11,12]
for i in list2:
    list1.append(i)
print(list1)
list2 = [10,11,12]
list1 = list1+list2
print(list1)
print(list1[2:5:1])
list1 = [0,1,2,3]
list1[2:3] = [13,14]
print(list1)


#进阶
my_list = [3, "apple", 9, "banana", 7, "cherry", 2, "data", 5, "elderberry"]
my_list.append("fig")
my_list.remove("banana")
my_list[my_list.index(7)] = "grape"
index_cherry = my_list.index("cherry")
my_list.insert(index_cherry+1, "kiwi")
index_3 = my_list[2]
sle_index = my_list[-2]
sl = my_list[2:7]
resevered_list = my_list[::-1]
nums = [i for i in my_list if isinstance(i, int)]
strs = [i for i in my_list if isinstance(i, str)]
sorted_strs = sorted(strs)
result = []
idx = 0
for item in my_list:
    if isinstance(item, int):
        result.append(item)
    else:
        result.append(sorted_strs[idx])
        idx += 1
# print("字符串排序后: ",result)
num_to_str = {1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven', 8 : 'eight', 9 : 'nine'}
new_my_list = []
for item in my_list:
    if isinstance(item, int):
        new_my_list.append(num_to_str.get(item, str(item)))
    else:
        new_my_list.append(item)
print(new_my_list)
print(resevered_list)
print(sl)
print(sle_index)
print(index_3)
for item in my_list:
    print(item)
print(index_cherry)
print(my_list)


#复杂
import random
even_list = [i for i in range(1,101) if i % 2 == 0]
squared_list = [i **2 for i in even_list]
squared_list = [i for i in squared_list if i <= 1000]
reversed_list = squared_list[::-1]
first_10 = reversed_list[:10]
new_list = [101,102,103]
reversed_list.extend(new_list)
average = sum(reversed_list)/len(reversed_list)
max_xal = max(reversed_list)
min_xal = min(reversed_list)
try:
    index_11 = reversed_list.index(11)
except ValueError:
    print("无11")

str_list_for = [str(i) for i in reversed_list]
print(str_list_for)
float_list = [float(i) for i in str_list_for]
count_list =sum(1 for i in float_list if i > 50)
float_list.insert(2, 99)
float_list.pop()
new_list2 = [i*2 for i in float_list]
less_list = [i for i in new_list2 if i <= 50]
greater_list = [i for i in new_list2 if i >50]
list_to_dict = {value: index for index, value in enumerate(float_list)}
print(list_to_dict)
for index, value in enumerate(float_list):
    print(f"索引{index}, 值{value}")
random_element = random.choice(float_list)
print(random_element)
with open("list_to_file",'w') as f:
    for item in float_list:
        f.write(str(item) + "\n")
print("列表已保存")
print(less_list)
print(greater_list)
# print(new_list2)
print(float_list)
print(count_list)
print(float_list)
print(squared_list)
print(reversed_list)
print(first_10)
print(average)
print(max_xal)
print(min_xal)